package com.jsz.peini.server.thread;

import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import com.alibaba.fastjson.JSONObject;
import com.alipay.api.domain.UseTime;
import com.jsz.peini.bean.user.UserInfo;
import com.jsz.peini.bean.user.UserSms;
import com.jsz.peini.common.util.AppPush;
import com.jsz.peini.common.util.PeiniUtils;
import com.jsz.peini.common.util.SmsSendUtil;
import com.jsz.peini.common.util.SpringContextUtil;
import com.jsz.peini.mapper.user.UserConcernMapper;
import com.jsz.peini.mapper.user.UserSmsMapper;
import com.jsz.peini.vo.UserConcerVo;

public class UserSquareThread extends Thread{
Logger logger = Logger.getLogger(UserRegThread.class);
	public static BlockingQueue<UserConcerVo> userInfo = new LinkedBlockingQueue<UserConcerVo>();

	private UserConcernMapper userConcernMapper;

	private UserSmsMapper userSmsMapper;
	
	public void init(){
		this.start();
	}
	
	@Override
	public void run() {
		super.run();
		userConcernMapper = (UserConcernMapper)SpringContextUtil.getBean(UserConcernMapper.class);
		
		while(true)
		{
			try {
				UserConcerVo userInfo = this.userInfo.take();
				List<LinkedHashMap<String, Object>> userinfo=userConcernMapper.getUserInfoByOtherId(userInfo.getId());
				if (userInfo.getBytype()==1) {
					for (int i = 0; i < userinfo.size(); i++) {
						//消息推送
						/*JSONObject object = new JSONObject();
						object.put("title", "系统消息");
						object.put("content", "您关注的用户“"+PeiniUtils.updateNickName(userInfo.getNickname(), userInfo.getAccCode())+"”，发布了一条广场新动态，快去看看吧~");
						object.put("type", 205);
						object.put("paramId", userInfo.getId());
						AppPush.sendPush(object,userinfo.get(i).get("userPhone").toString().split(","));*/
						
						//给发起人推送消息						
						SmsSendUtil.sendSmsFit(null, userinfo.get(i).get("userId").toString(), userInfo.getId(), 205, "您关注的用户“"+PeiniUtils.updateNickName(userInfo.getNickname(), userInfo.getAccCode())+"”，发布了一条广场新动态，快去看看吧~");
					}
				}else if (userInfo.getBytype()==2){
					for (int i = 0; i < userinfo.size(); i++) {
						//消息推送
						JSONObject object = new JSONObject();
						object.put("title", "系统消息");
						object.put("content", "您关注的用户“"+PeiniUtils.updateNickName(userInfo.getNickname(), userInfo.getAccCode())+"”，发布了一个新任务，快去看看吧~");
						object.put("type", 206);
						object.put("paramId", userInfo.getTaskId());
						AppPush.sendPush(object,userinfo.get(i).get("userPhone").toString().split(","));
						//给发起人推送消息
						SmsSendUtil.sendSmsFit(null, userinfo.get(i).get("userId").toString(), userInfo.getTaskId().toString(), 206, "您关注的用户“"+PeiniUtils.updateNickName(userInfo.getNickname(), userInfo.getAccCode())+"”，发布了一个新任务，快去看看吧~");
					}
				}else if (userInfo.getBytype()==3){
					for (int i = 0; i < userinfo.size(); i++) {
						//消息推送
						/*JSONObject object = new JSONObject();
						object.put("title", "系统消息");
						object.put("content", "您关注的用户“"+PeiniUtils.updateNickName(userInfo.getNickname(), userInfo.getAccCode())+"”，上传了一批新照片，快去看看吧~");
						object.put("type", 207);
						object.put("paramId", userInfo.getId());
						AppPush.sendPush(object,userinfo.get(i).get("userPhone").toString().split(","));*/
						//给发起人推送消息
						SmsSendUtil.sendSmsFit(null, userinfo.get(i).get("userId").toString(), userInfo.getId(), 207, "您关注的用户“"+PeiniUtils.updateNickName(userInfo.getNickname(), userInfo.getAccCode())+"”，上传了一批新照片，快去看看吧~");
					}
				}
				Thread.sleep(1);
			} catch (Exception e1) {
				e1.printStackTrace();
				logger.info("fail", e1);
			}
		}
		
	}

}
